package com.wbr.springboot.sbproject.controller;

import com.wbr.springboot.sbproject.po.UserInfo;
import com.wbr.springboot.sbproject.service.UserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("/userinfo")
@Controller
public class UserInfoController {

    private final Logger log = LoggerFactory.getLogger(CountController.class);
    @Autowired
    private UserInfoService userInfoService;

    @RequestMapping("/add")
    public void addUser(@RequestParam String username, @RequestParam String password){
        userInfoService.addUser(username, password);
    }

    @RequestMapping("/getuserbyname")
    @ResponseBody
    public UserInfo getUserByName(@RequestParam String username){
        return userInfoService.findUserByName(username);
    }

    @RequestMapping("/getalluser")
    @ResponseBody
    public List<UserInfo> getAllUser(){
        log.info("获取所有用户信息！");
        return userInfoService.getAllUSer();
    }
}
